package com.xique.client.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xique.client.bean.domain.PayOrder;
import com.xique.client.bean.search.PayOrderSearch;
import com.xique.client.mapper.PayOrderMapper;
import com.xique.client.service.service.IPayOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author shd
 * @create 2021/11/4 10:17
 */
@Service
public class PayOrderServiceImpl implements IPayOrderService {

    @Autowired
    private PayOrderMapper payOrderMapper;

    @Override
    public PayOrder selectPayOrder(PayOrderSearch search) {
        QueryWrapper<PayOrder> wrapper = new QueryWrapper<>();
        if (null != search.getLaneId()) {
            wrapper.eq("pay_lane_id", search.getLaneId());
        }
        if (null != search.getStatus()) {
            wrapper.eq("status", search.getStatus());
        }
        wrapper.orderByDesc("create_time")
                .last("limit 1");

        return payOrderMapper.selectOne(wrapper);
    }

    @Override
    public Double selectElectronicStatistic(Long parkId) {
        return payOrderMapper.selectElectronicStatistic(parkId);
    }

    @Override
    public Double selectCashStatistic(Long parkId) {
        return payOrderMapper.selectCashStatistic(parkId);
    }

    @Override
    public Double selectCashStatisticByUserId(Long parkId, Long userId) {
        return payOrderMapper.selectCashStatisticByUserId(parkId, userId);
    }

    @Override
    public Double selectWaitStatistic(Long parkId) {
        return payOrderMapper.selectWaitStatistic(parkId);
    }

    @Override
    public Double selectFreeStatistic(Long parkId) {
        return payOrderMapper.selectFreeStatistic(parkId);
    }

    @Override
    public Double selectFreeStatisticByUserId(Long parkId, Long userId) {
        return payOrderMapper.selectFreeStatisticByUserId(parkId, userId);
    }
}
